﻿namespace TomatoBreak.DomainObjects
{
    using System;
    using System.Diagnostics;

    using Infrastructure;

    [DebuggerDisplay("{Name}")]
    public class Task : Entity
    {
        private string name;
        private bool planned;
        private User user;
        private DateTime createdAt;

        [Obsolete("Used by the ORM")]
        public Task()
        {
        }

        public Task(User user, string name, DateTime createdAt)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            this.name = name;
            this.createdAt = createdAt;
            this.user = user;

            planned = true;
        }

        public virtual string Name
        {
            [DebuggerStepThrough]
            get { return name; }

            [DebuggerStepThrough]
            set { name = value; }
        }

        public virtual bool Planned
        {
            [DebuggerStepThrough]
            get { return planned; }

            [DebuggerStepThrough]
            set { planned = value; }
        }

        public virtual string Notes { get; set; }

        public virtual int? Estimation { get; set; }

        public virtual DateTime CreatedAt
        {
            [DebuggerStepThrough]
            get { return createdAt; }

            [DebuggerStepThrough]
            protected set { createdAt = value; }
        }

        public virtual DateTime? DueAt { get; set; }

        public virtual DateTime? CompletedAt { get; protected set; }

        public virtual bool Archived { get; protected set; }

        public virtual User User
        {
            [DebuggerStepThrough]
            get { return user; }

            [DebuggerStepThrough]
            protected set { user = value; }
        }

        public virtual void Complete()
        {
            CompletedAt = Clock.UtcNow();
        }

        public virtual void Archive()
        {
            Archived = true;
        }
    }
}